The Extensible Markup Language (XML) is the standard for data and documents that is finding wide acceptance in the computer industry. XML describes and provides structure to a body of data, such as a file or data packet, referred to herein as a XML entity. The XML standard provides for tags that delimit sections of a XML entity referred to as XML elements. Each XML element may contain one or more name-value pairs referred to as attributes. The following XML Segment A is provided to illustrate XML.
SEGMENT A<book>My book  <publication publisher=”Doubleday”      date=”January”></publication>  <Author>Mark Berry</Author>  <Author>Jane Murray</Author></book>
XML elements are delimited by a start tag and a corresponding end tag. For example, segment A contains the start tag <Author> and the end tag </Author> to delimit an element. The data between the elements is referred to as the element's content. In the case of this element, the content of the element is the text data Mark Berry.
Element content may contain various other types of data, which include attributes and other elements. The book element is an example of an element that contains one or more elements. Specifically, book contains two elements: publication and author. An element that is contained by another element is referred to as a descendant of that element. Thus, elements publication and author are descendants of element book. An element's attributes are also referred to as being contained by the element.
By defining an element that contains attributes and descendant elements, the XML entity defines a hierarchical tree relationship between the element, its descendant elements, and its attribute. A root node and a set of elements that descend from the root node are referred to herein as a XML document.
XML Data Models
An important standard for XML is the XQuery 1.0 and XPath 2.0 Data Model. (see W3C Working Draft, 29 Oct. 2004), which is incorporated herein by reference and referred to hereinafter as the XQuery Data Model.
One aspect of XQuery Data Model is that XML data is represented by a hierarchy of nodes that reflects the hierarchical nature of the XML data. A hierarchy of nodes is composed of nodes at multiple levels. The nodes at each level are each linked to one or more nodes at a different level. Each node at a level below the top level is a child node of one or more of the parent nodes at the level above. Nodes at the same level are sibling nodes. In a tree hierarchy or node tree, each child node has only one parent node, but a parent node may have multiple child nodes. In a tree hierarchy, a node that has no parent node linked to it is the root node, and a node that has no child nodes linked to it is a leaf node. A tree hierarchy has a single root node.
In a node tree that represents a XML document, a node can correspond to an element, the child nodes of the node correspond to an attribute or another element contained in the element. The node may be associated with a name and value. For example, for a node tree representing the element book, the name of the node associated with element book is book, and the value is ‘My book’. For a node representing the attribute publisher, the name of the node is publisher and the value of the node is ‘Doubleday’.
For convenience of expression, elements and other parts of a XML document are referred to as nodes within a tree of nodes that represents the document. Thus, referring to ‘My book’ as the value of the node with name book is just a convenient way of expressing the value of the element associated with node book is My book.
A XML fragment is a portion of a XML document. A XML fragment can be a subtree within a XML document. A XML fragment may also be an attribute, an element, or a XML sequence (“sequence”) of elements that descend from parent node but does not include the parent node.
Finally, the term XML value is used herein to refer to any value stored or represented by a XML document or parts thereof. A XML value may be a scalar value, such as the string value of an element and the numeric value of an attribute-value pair; a XML value may be a XML fragment, or a XML document. The term XML value refers to any value represented by the XQuery Data Model.
XML Storage and Query Mechanisms
Various types of storage mechanisms are used to store a XML document. One type of storage mechanism stores a XML document as a text file in a file system.
Another type of storage mechanism uses object-relational database systems that have been enhanced to store and query XML values. In an embodiment, a XML document is stored in a row of a table and nodes of the XML document are stored in separate columns in the row. An entire XML document may also be stored in a lob (large object). A XML document may also be stored as a hierarchy of objects in an object-relational database; each object is an instance of an object class and stores one or more elements of a XML document. The object class defines, for example, the structure corresponding to an element, and includes references or pointers to objects representing the immediate descendants of the element. Tables and/or objects of a database system that hold XML values are referred to herein as base tables or objects.
It is important for object-relational database systems that store XML values to be able to execute queries using XML query languages, such as XQuery/XPath. XML Query Language (“XQuery”) and XML Path Language (“XPath”) are important standards for a query language, which can be used in conjunction with SQL to express a large variety of useful queries. XPath is described in XML Path Language (XPath), version 1.0 (W3C Recommendation 16 Nov. 1999), which is incorporated herein by reference. XPath 2.0 and XQuery 1.0 are described in XQuery 1.0 and XPath 2.0 Full-Text. (W3C Working Draft 9 Jul. 2004), which is incorporated herein by reference.
Queries that request XML values often request multiple XML values from the same XML document or fragment. However, the computation of such a query is performed in a way such that, for the particular row that holds the requested XML document or fragment, the row is accessed multiple times, once for each of the multiple XML values of the XML document. The following query QB is provided as an illustration.
select  extract (po, ‘/PurchaseOrder/Pono’),  extract (po, ‘/PurchaseOrder/BillingAddress’),....  from po_table;
Each row in base table po_table holds a XML document. For each such document, the row that contains the XML document is accessed for each of the Extract function invocations in query QB.
Based on the foregoing, there is a need for a more efficient approach for computing queries that request XML values from a XML document.
The approaches described in this section are approaches that could be pursued, but not necessarily approaches that have been previously conceived or pursued. Therefore, unless otherwise indicated, it should not be assumed that any of the approaches described in this section qualify as prior art merely by virtue of their inclusion in the BACKGROUND section.